//
//  NMPOTabBarViewController.swift
//  NMPO
//
//  Created by PowerfullClean on 2023/10/31.
//

import UIKit

class NMPOTabBarViewController: UITabBarController, UITabBarControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
//        tabBar.backgroundColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0x10193D)
        tabBar.addSubview(nmpo_bgView)
        nmpo_bgView.snp.makeConstraints { make in
            make.bottom.left.width.equalToSuperview()
            make.height.equalTo(NMPOCommon.nmpo_tabbarH+10)
        }
        delegate = self
    }
    
    func nmpo_createChildVC(nmpo_controllers:[UIViewController])  {
        var nmpo_arr = [UIViewController]()
        for nmpo_vc in nmpo_controllers {
            let nmpo_nav = NMPONavBarViewController(rootViewController: nmpo_vc)
            nmpo_arr.append(nmpo_nav)
        }
        viewControllers = nmpo_arr
        
        nmpo_setItmes(nmpo_images: ["nmpo_tab_home1","nmpo_tab_fun1"], nmpo_selectedImages: ["nmpo_tab_home2","nmpo_tab_fun2"])
    }
    func nmpo_setItmes(nmpo_images:[String]?,nmpo_selectedImages:[String]?) {
        var i:NSInteger = 0
        for item in tabBar.items! {
            item.tag = i
            if (nmpo_images?.count)! > 0 {
                
                item.image = UIImage.init(named:  nmpo_images![i])?.withRenderingMode(.alwaysOriginal)
                
            }
            if (nmpo_selectedImages?.count)! > 0 {
                
                item.selectedImage = UIImage.init(named: nmpo_selectedImages![i])?.withRenderingMode(.alwaysOriginal)
            }
            
            i += 1
        }
    }
    func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
        nmpo_bgView.image = UIImage(named: "nmpo_tab_icon\(self.selectedIndex+1)")
    }
    lazy var nmpo_bgView: UIImageView = {
        let nmpo_bgView = UIImageView(image: UIImage(named: "nmpo_tab_icon1"))
        return nmpo_bgView
    }()
}


